﻿using EmitDebugging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Spackle.Testing;
using System;
using System.Reflection;

namespace EmitDebugging.Tests
{
	[TestClass]
	public sealed class ManagedCalliDescriptorTests : CoreTests
	{
		[TestMethod]
		public void GetDescription()
		{
			Assert.AreEqual("standard hasthis int32(uint8, valuetype System.Guid)",
				new ManagedCalliDescriptor(CallingConventions.Standard | CallingConventions.HasThis, 
					typeof(int), new Type[] { typeof(byte), typeof(Guid) }, null).Value);
		}

		[TestMethod]
		public void GetDescriptionWithVarArgArgumentsButConventionIsNotVarArg()
		{
			Assert.AreEqual("standard hasthis int32(uint8, valuetype System.Guid)",
				new ManagedCalliDescriptor(CallingConventions.Standard | CallingConventions.HasThis,
					typeof(int), new Type[] { typeof(byte), typeof(Guid) },
					new Type[] { typeof(byte), typeof(Guid) }).Value);
		}

		[TestMethod]
		public void GetDescriptionWithVarArgConvention()
		{
			Assert.AreEqual("varargs int32(uint8, valuetype System.Guid, ..., uint8, valuetype System.Guid)",
				new ManagedCalliDescriptor(CallingConventions.VarArgs,
					typeof(int), new Type[] { typeof(byte), typeof(Guid) },
					new Type[] { typeof(byte), typeof(Guid) }).Value);
		}

		[TestMethod]
		public void GetDescriptionWithVarArgConventionAndNoVarArgArgumentsGiven()
		{
			Assert.AreEqual("varargs int32(uint8, valuetype System.Guid, ...)",
				new ManagedCalliDescriptor(CallingConventions.VarArgs,
					typeof(int), new Type[] { typeof(byte), typeof(Guid) },
					Type.EmptyTypes).Value);
		}
	}
}
